<script setup>
import { ref } from 'vue';
import { saveMemberLevelApi } from'@/apis/member/memberLevel.js';

// 刷新页面数据
const emits = defineEmits(['refreshData'])

// 展示面板
const dialogVisible = ref(false)
const title = ref('')

// 数据
const memberLevelData = ref({})

// 初始化
const init=async(id)=>{
    if(id===null || id==='' || id===void 0){
        memberLevelData.value = {};
        title.value = '添加'
        dialogVisible.value = true;
    // }else{
    //     memberLevelData.value={};
    //     title.value = '修改'
    //     const res = await getBrandInfoApi(id);
    //     memberLevelData.value = res.data;
    //     dialogVisible.value = true;
    // }
}
}

defineExpose({
    init,
})

// 点击确定
const handleConfirm=()=>{
    if(memberLevelData.value.id === null || memberLevelData.value.id === void 0 || memberLevelData.value.id === ''){
        // 添加
        saveMemberLevelApi(memberLevelData.value)
        .then(res=>{
            if(res.code === 0){
                ElMessage({
                    message: '添加成功',
                    type: 'success',
                })
                dialogVisible.value = false;
            }
        })
    }
}

</script>

<template>
    <el-dialog v-model="dialogVisible" :title="title" style="width: 35%;">
    <el-form 
        :model="memberLevelData" 
        :rules="rules" 
        ref="dataForm" 
        status-icon
        label-width="160px"
        >
    <el-form-item label="等级名称" prop="name">
        <el-input v-model="memberLevelData.name" placeholder="等级名称"></el-input>
    </el-form-item>
    <el-form-item label="等级需要的成长值" prop="growthPoint">
        <el-input-number v-model="memberLevelData.growthPoint" :min="0" :precision="2" style="width: 80%;"/>
    </el-form-item>
    <el-form-item label="是否为默认等级" prop="defaultStatus">
        <el-switch
            v-model="memberLevelData.defaultStatus"
            class="mb-2"
            :active-value="0"
            :inactive-value="1"
            active-text="是"
            inactive-text="否"
        />
    </el-form-item>
    <el-form-item label="免运费标准" prop="freeFreightPoint">
        <el-input-number v-model="memberLevelData.freeFreightPoint" :min="0" :precision="2" style="width: 80%;"/>
    </el-form-item>
    <el-form-item label="每次评价获取的成长值" prop="commentGrowthPoint">
        <el-input-number v-model="memberLevelData.commentGrowthPoint" :min="0" :precision="2" style="width: 80%;"/>
    </el-form-item>
    <el-form-item label="是否有免邮特权" prop="privilegeFreeFreight">
        <el-switch
            v-model="memberLevelData.privilegeFreeFreight"
            class="mb-2"
            :active-value="0"
            :inactive-value="1"
            active-text="是"
            inactive-text="否"
        />
    </el-form-item>
    <el-form-item label="是否有会员价格特权" prop="priviledgeMemberPrice">
        <el-switch
            v-model="memberLevelData.privilegeMemberPrice"
            class="mb-2"
            :active-value="0"
            :inactive-value="1"
            active-text="是"
            inactive-text="否"
        />
    </el-form-item>
    <el-form-item label="是否有生日特权" prop="privilegeBirthday">
        <el-switch
            v-model="memberLevelData.privilegeBirthday"
            class="mb-2"
            :active-value="0"
            :inactive-value="1"
            active-text="是"
            inactive-text="否"
        />
    </el-form-item>
    <el-form-item label="备注" prop="note">
        <el-input v-model="memberLevelData.note" placeholder="备注" type="textarea"></el-input>
    </el-form-item>
    </el-form>
    <template #footer>
        <span class="dialog-footer">
            <el-button @click="dialogVisible = false">取消</el-button>
            <el-button type="primary" @click="handleConfirm">确定</el-button>
        </span>
    </template>
  </el-dialog>
</template>

<style scoped lang='scss'>

</style>